package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-08-19
 * Time: 16:47
 */
//单例模式—饿汉式
class School {
    private static School school = new School();
    private School() {

    }
    public static School getSchool() {
        return school;
    }
}

//单例模式-懒汉式
class Hospital {
    private static Hospital hospital;
    private Hospital() {

    }
    public static Hospital getHospital() {
        if(hospital == null) {
            hospital = new Hospital();
        }
        return hospital;
    }
}
public class Test01 {
    public static void main1(String[] args) {
        School student1 = School.getSchool();
        School student2 = School.getSchool();
        System.out.println(student1 == student2);
    }
}
